<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2018-05-29
  Time: 14:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>挂号</title>
    <%@ include file="../statics/AllJavaScript.jsp" %>
</head>
<body>
<div class="panel panel-default">
    <div class="panel-body">
        <form class="form-inline">
            <div class="form-group">
                姓名：<input id="pName" name="pName" type="text" lang="zh-CN" class="form-control" placeholder="搜索内容"/>
            </div>
            <div class="form-group">
                挂号编号:<input id="rCode" name="pName" type="text" lang="zh-CN" class="form-control" placeholder="搜索内容"/>
            </div>
            <div class="dropdown"  style="display: inline-block">
                <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1"
                        data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                    <span class="selectInfo1">请选择</span>
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" id="selectItem" aria-labelledby="dropdownMenu1">
                    <li><a href="JavaScript:" onclick="seleInfo(1)">未预约</a></li>
                    <li><a href="javaScript:" onclick="seleInfo(2)">已预约</a></li>
                </ul>
            </div>
            <button onclick="search()" type="button" class="btn btn-default">查询</button>
        </form>
    </div>
</div>
<input type="text" style="display: none" id="selectId" value="0"/>
<table id="table"></table>

</body>
<script type="text/javascript">
     function seleInfo(id){
         $(".selectInfo1").html(id==1?"未预约":"已预约");
         $("#selectId").val(id);
     }
    $(function () {
        $("#table").bootstrapTable({
            url: '${pageContext.request.contextPath}/register/getRegisterInfo',
            columns: [{
                field:"r_code",
                title:"挂号编号"
            },
                {
                field: 'p_id',
                title: '患者编号'
            }, {
                field: 'p_name',
                title: '患者姓名'
            }, {
                field: 'p_sex',
                title: '患者性别'
            }, {
                field: 'p_cards',
                title: '患者身份证号'
            }, {
                field: 'p_emal',
                title: '患者邮箱'
            }, {
                field: 'p_BirthDate',
                title: '患者生日',
                    formatter:function (value,row,index) {
                        return jsonDateFormat(row.p_BirthDate);
                    }
            },{
                title:"是否预约",
                field:"r_stat",
                formatter:function (value,row,index) {
                    switch (row.r_stat){
                        case 1:
                            return "未预约";
                        case 2:
                            return "已预约";
                    }
                }
            }],
            method:"post",
            contentType: "application/x-www-form-urlencoded",
            height: 500,
            pageList: [5, 10, 15],
            pageSize: 5,
            pageNumber: 1,
            pagination: true,
            sidePagination: 'server',
            dataView:true,
            queryParamsType:"",
            queryParams:queryParmer
        })
    });
    function queryParmer(parmers) {
        var temp={
            "name":$("#pName").val(),
            "pageSize":parmers.pageSize,
            "pageNumber":parmers.pageNumber,
            "rStat":$("#selectId").val(),
            "rCode":$("#rCode").val()
        }
        return temp;
    }
    
    function search() {
        var option=$("#table").bootstrapTable("getOptions")
        var Code=$("#rCode").val();
        var name=$("#pName").val();
        var stat=$("#selectId").val();
        $.ajax({
            url:"${pageContext.request.contextPath}/register/getRegisterInfo",
            data:{"rCode":Code,"name":name,"pageNumber":option.pageNumber,"pageSize":option.pageSize,"rStat":stat},
            datatype:"json",
            method:"post",
            "success":function (data) {
                $("#table").bootstrapTable("load",data);
            }
        })
    }
     function jsonDateFormat(jsonDate) {
         //json日期格式转换为正常格式
         var jsonDateStr = jsonDate.toString();//此处用到toString（）是为了让传入的值为字符串类型，目的是为了避免传入的数据类型不支持.replace（）方法
         try {
             var k = parseInt(jsonDateStr.replace("/Date(", "").replace(")/", ""), 10);
             if (k < 0)
                 return null;

             var date = new Date(parseInt(jsonDateStr.replace("/Date(", "").replace(")/", ""), 10));
             var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
             var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
             var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
             var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
             var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
             var milliseconds = date.getMilliseconds();
             return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
         }
         catch (ex) {
             return "时间格式转换错误";
         }
     }
</script>
</html>
